3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
QuickDraw 3D provides routines to register and unregister a shared library.
These routines let you provide an entry point for Windows dynamic link libraries or an initialization function for Mac OS shared libraries. Some libraries need to be loaded in a specific order; the registration mechanism lets QuickDraw 3D load libraries in the order that it needs to, and not be bound by the order of shared libraries on disk (for example, in the Mac OS Extensions folder).
The Q3XSharedLibrary_Register routine notifies QuickDraw 3D that there is a library to be loaded and provides the entry point to the registration function. To use this function you need to fill out a TQ3XSharedLibraryInfo block, which provides information that the system will need to load the library.
Usually the Q3XSharedLibrary_Register function will be called from the shared library entry point. See the documentation for your development system, or the examples on the QuickDraw 3D SDK, for information about how to set this up. The Q3XSharedLibrary_Unregister function is used to unregister the library. It is usually called from the shared library termination routine. Windows programming is slightly different because a single DLLMain function is called with a selector for registration and unregistration.
The code in Listing 6 illustrates register and unregister functions for both Windows and Mac OS. It is taken from the sample renderer example on the QuickDraw 3D SDK. In the windows version there is a switch statement for registration and unloading, whereas in the Mac OS version these processes are handled by two distinct functions.
Listing 6 Library registering and unregistering
/* Mac OS registration & termination */
OSErr SR_Initialize(
const CFragInitBlock *initBlock)
{
TQ3XSharedLibraryInfo sharedLibraryInfo;
OSErr err = noErr;
sharedLibraryInfo.registerFunction = SR_Register;
sharedLibraryInfo.sharedLibrary
= (unsigned long)initBlock->connectionID;
Q3XSharedLibrary_Register(&sharedLibraryInfo);
SRgSharedLibrary = (unsigned long)initBlock->connectionID;
err = SR_CreateAliasHandle(initBlock);
return (err);
}
TQ3Status SR_Exit(
void)
{
if (SRgSharedLibrary != NULL) {
Q3XSharedLibrary_Unregister(SRgSharedLibrary);
SRgSharedLibrary = NULL;
}
SR_FreeAliasHandle();
return (kQ3Success);
}
/* Win32 extension entry point*/
HINSTANCE hinstMyDLL = NULL;
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
TQ3XSharedLibraryInfo sharedLibraryInfo;
if (fdwReason == DLL_PROCESS_ATTACH) {
hinstMyDLL = hinstDLL;
sharedLibraryInfo.registerFunction = SR_Register;
sharedLibraryInfo.sharedLibrary = (unsigned long)hinstDLL;
if (Q3XSharedLibrary_Register(&sharedLibraryInfo) == kQ3Success) {
return TRUE;
} else {
return FALSE;
}
}
if (fdwReason == DLL_PROCESS_DETACH) {
Q3XSharedLibrary_Unregister((unsigned long)hinstDLL);
}
return (TRUE);
}
You can use the Q3XSharedLibrary_Register function to notify QuickDraw 3D that there is a library to be loaded and provide the entry point to the library's registration function.
typedef struct TQ3XSharedLibraryInfo {
TQ3XSharedLibraryRegister registerFunction;
unsigned long sharedLibrary;
} TQ3XSharedLibraryInfo;
TQ3Status Q3XSharedLibrary_Register(
TQ3XSharedLibraryInfo *sharedLibraryInfo);
You can use the Q3XSharedLibrary_Unregister function to unregister a QuickDraw 3D shared library.
TQ3Status Q3XSharedLibrary_Unregister(
unsigned long sharedLibrary);
Previous | QD3D Book | Overview | Chapter Contents | Next |